import { createStore } from 'vuex'
interface Obj {
  name: string;
  age: number;
  sex: string;
}

function f8<T>(n1:T,n2:T):T[]{
          return [n1,n2]
      };
      f8<string>('1','2');
let f1= ():[] => {
  return []
}
type ctx = {
  commit?:any,
  dispatch?:any,
  getters?:any,
  state?:any}
type Store = {
  state:{
    [things:string]:any
  },
  mutations:{
    [things:string]:(state:any,data:any)=> void
  },
  actions?:{
    [things:string]:(ctx:ctx,data:any)=> void
  },
  modules?:any,
  getters?:any
}
const create:Store = {
  state: {
    obj: {
      name: '123',
      age: 21,
      sex: '男'
    },
    user: "liu",
    pass: "yong",
    page: [],
    index: 0,
    info: "100",
    phone: "",
    search: "",
    text: "",
    book: "",
    isCollapse:false
  },
  mutations: {
    ina: function (state,data) {
      state.index = state.index + data
    },
    hello(state:any, a) {//两个回调参数一个state，一个形参
      console.log("hello world" + a.a + state.pass)
      state.user = "liuyu"
  },
  page(state) {
      const data = {
          params: {
              a: state.index
          }
      }
      // axios.get("publica/index/Api/page", data, { headers: { "Content-Type": "application/json" } }).then(res => {
      //     state.page = res.data.b
      // })
  },
  zhu(state, pho) {
      const ph = {
          phone: pho
      }
      const header = {
          headers: {
              "Content-Type": "application/x-www-form-urlencoded"
          }
      }
      // axios.post("publica/index/Api/zhu", qs.stringify(ph), header).then(res => {
      //     state.info = res.data
      // })
  },
  search(state) {
      const data = {
          params: {
              inf: null
          }
      }
      const header = {
          headers: {
              "Content-Type": "application/json"
          }
      }
      // axios.get("publica/index/Api/search", data, header).then(res => {
      //     state.text = res.data
      // })
  },
  async book(state) {
      const data = {
          params: {
              book: null
          }
      }
      const header = {
          headers: {
              "Content-Type": "application/json"
          }
      }
      // let info = await http('get','/search',{name:1})
      // console.log(info)
      //     let arr = []
      //     info.data.map ((x, index) => {
      //         arr[index] = {value: x.name}
      //     })
      //     state.book = arr
      // http('get','/search',{name:1}).then(res => {
      //     let arr = []
      //     res.data.map ((x, index) => {
      //         arr[index] = {value: x.name}
      //     })
      //     state.book = arr
      // })
      // axios.get("publica/index/Api/book", data, header).then(res => {
      //     state.book = res.data
      // })
  }
  },
  actions: {
    ind: function ({commit},data) {
      commit('ina',data)
    },
    hel(con) {//{commit}
        con.commit("hello", { a: 10, b: 11 })
    },
    page(con) {
        con.commit("page",);
    },
    zhu(con, state) {
        con.commit("zhu", state.phone)
    },
    search(con) {
        con.commit("search")
    },
    book(con) {
        con.commit("book")
    }
  },
  modules: {
  },
  getters: {
    liu: function (state:any) {
      return state.obj
    },
    indexa: function (state:any) {
      return state.index
    },
    he(state:any) {
      return state.user;
  },
  isCollapse:(state:any)=>state.isCollapse
  }
}
export default createStore({...create})
